package com.itheima.tanhua.apiImpl;

import com.itheima.tanhua.pojo.mongo.Friend;
import com.itheima.tanhua.pojo.mongo.MovementTimeLine;
import com.itheima.tanhua.api.mongodb.TimeLineApi;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;

import java.util.List;

@DubboService
public class TimeLineApiImpl implements TimeLineApi {

    @Autowired
    private MongoTemplate mongoTemplate;

    @Override
    public List<Friend> findFriends(Long uid) {
        Query query=Query.query(Criteria.where("userId").is(uid));
        return mongoTemplate.find(query, Friend.class);
    }

    @Override
    public void saveMovementTimeLine(MovementTimeLine movementTimeLine) {

        mongoTemplate.save(movementTimeLine);
    }

    //需要转化思路 将uid作为Fid  即和我有朋友关系的人发的动态
    @Override
    public List<MovementTimeLine> findTimeLine(Long uid) {

        Query query=Query.query(Criteria.where("friendId").is(uid));
        return  mongoTemplate.find(query, MovementTimeLine.class);


    }
}
